﻿import QtQuick 2.0
import QtQuick.Layouts 1.12
import QtQuick.Controls 2.12
Rectangle {
    id: root
    anchors.fill: parent
    function setData(data){
        logModel.clear()
        for(let i = data.length-1; i >=0; i --){
            logModel.append({
                                "Item1": data[i][0],
                                "Item2": data[i][1],
                                "Item3": data[i][2]
                            })
        }
    }


//    // 标题
//    Rectangle{
//        height: 40*dp
//        width: root.width
//        Text{
//            text: "实验日志"
//            font.bold: true
//            font.pixelSize: config.fontsize + 6
//            anchors.verticalCenter: parent.verticalCenter
//        }
//    }

    // 表头
    Rectangle{
        y: 45*dp
        height: 40*dp
        width: root.width
        color: "#E6E6E6"
        Rectangle{              // 表格线
            color: "white"
            height: parent.height - 2
            width: parent.width
            y: 1; x: 0
        }
        Item{
            height: parent.height
            width: parent.width/6*1.8
            x:parent.width/6*0
            Text{
                text: "时间"
                anchors.centerIn: parent
                color: "#888888"
                font.pixelSize: config.fontsize
            }
        }Item{
            height: parent.height
            width: parent.width/6
            x: parent.width/6*1.9
            Text{
                text: "动作"
                anchors.centerIn: parent
                color: "#888888"
                font.pixelSize: config.fontsize
            }
        }Item{
            height: parent.height
            width: parent.width/6*3
            x: parent.width/6*2.8
            Text{
                text: "指令"
                anchors.centerIn: parent
                color: "#888888"
                font.pixelSize: config.fontsize
            }
        }
    }

    ListView{
        y: 85*dp
        height: root.height - 85*dp
        width: root.width
        model: logModel
        delegate: logDelegate
        clip: true
    }
    ListModel{
        id: logModel
    }Component{
        id: logDelegate
        Rectangle{
            height: 80*dp
            width: root.width
            Rectangle{
                height: 1
                width: root.width
                color: "#E6E6E6"
                y: parent.height - 1
            }
            Item{
                height: parent.height
                width: parent.width/6*1.8
                x:0*dp
                Text{
                    text: Item1
                    anchors.centerIn: parent
                    wrapMode: Text.WordWrap
                    font.pixelSize: config.fontsize
                }
            }Item{
                height: parent.height
                width: parent.width/6
                x: parent.width/6*1.9
                Text{
                    text: Item2
                    anchors.centerIn: parent
                    wrapMode: Text.WordWrap
                    font.pixelSize: config.fontsize
                }
            }Item{
                height: parent.height
                width: parent.width/6*3
                x: parent.width/6*3
                TextInput{
                    id:orderinfo
                    width: parent.width
                    text: Item3
                    anchors.centerIn: parent
                    font.pixelSize: config.fontsize
                    wrapMode: Text.WordWrap
                    selectByMouse: true //设置为可以被鼠标选中
                }
            }
        }
    }


}
